package kr.co.choongang;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class EmpSelectDAO implements EmpSelectInterface{
	private String driver;
	private String url;
	private String userid;
	private String passwd;
	private Connection conn;
	private Statement stmt;
	private ResultSet rs;		
	private String sql;
	private String emp_id;
	private String ename;
	private int salary;
	private String depart;
	private EmpSelectDTO empSelectDTO;
	public EmpSelectDAO() throws ClassNotFoundException {
		empSelectDTO = new EmpSelectDTO();
		driver = "oracle.jdbc.driver.OracleDriver";
		url = "jdbc:oracle:thin:@127.0.0.1:1521:XE";
		userid = "kdoing";
		passwd = "dkdlxl";
		Class.forName(driver);
	}
	@Override
	public void setConnection() throws SQLException{
		conn = DriverManager.getConnection(url, userid, passwd);
	}
	@Override
	public void setStatement(EmpSelectDTO dto) throws SQLException{
		stmt=conn.createStatement();
		sql = "select emp_id,ename,salary,depart from emp";
	}
	@Override
	public ResultSet executeQuerySelect() throws SQLException{
		rs = stmt.executeQuery(sql);
		return rs;
	}
	@Override
	public EmpSelectDTO setSelectResult() throws SQLException{
		empSelectDTO = new EmpSelectDTO(); 
		empSelectDTO.setEmp_id(rs.getString("emp_id"));
		empSelectDTO.setEname(rs.getString("ename"));
		empSelectDTO.setSalary(rs.getInt("salary"));
		empSelectDTO.setDepart(rs.getString("depart"));
		return empSelectDTO;
		
	}
	@Override
	public int executeQuery() throws SQLException {
		return 0;
	}
}
